<template>
	<view class="page hotel-orders" style="padding-bottom: 0;">
		<!-- 筛选 -->
		<view class="filter-bar flex-row-between">
			<block v-for="(item, index) in filterBar" :key="index">
				<view class="item" :class="{'active' : filterCurrent == item.id}" @click="filterList(item.id)">
					{{item.title}}
				</view>
			</block>
		</view>
		<!-- 列表 -->
		<LoadMore ref="LoadMore" id="LoadMore" :token="true" :diffHeight="92" :initData="initData"
			@dataRefresh='dataRefresh'>
			<view class="order-list">
				<block v-for="(item, index) in dataList" :key="index">
					<view class="box-shadow item">
						<view class="part1 font12 flex-row-between">
							<view class="font-theme">
								{{item.name_is}}
							</view>
							<uni-countdown v-if="item.down_is && item.timeobj.show" class="group-countdown"
								backgroundColor="rgba(255,255,255,.2)" color="#969696" splitorColor="#969696"
								:day="item.timeobj.day" :hour="item.timeobj.hour" :minute="item.timeobj.minute"
								:second="item.timeobj.second" :show-colon="false" />
						</view>
						<view class="part2 flex-row-start">
							<view class="image bg-cover"
								:style="{backgroundImage: 'url(' + imgFullUrl+item.order_goods.logo + ')'}"></view>
							<view class="info flex-column-between">
								<view class="font14">{{item.order_goods.goods_name}}</view>
								<view class="font12 font-969696">
									规格：{{item.order_goods.spec_type==10?'默认':item.order_goods.goods_attr}}</view>
								<view class="font12 flex-row-between">
									<view class="font-969696">x{{item.order_goods.total_num}}</view>
									<view>￥{{item.order_goods.goods_price}}</view>
								</view>
							</view>
						</view>
						<view class="part3 flex-row-between">
							<view class="font12">合计：<text
									class="font14 font-assist">￥{{item.pay_status==2?item.total_price:item.pay_price}}</text>
							</view>
							<view class="flex-row-end">
								<view v-if="item.refund_is" class="btn" @click="goNext('/pages/group/after?code='+item.order_no)">售后详情</view>
								<view v-if="!item.refund_is && item.is_spell==1 && item.pay_status == 1" class="btn"
									@click="goNext('/pages/group/progress?id='+item.spell_info.id)">拼团详情</view>
								<view class="btn blue" @click="goNext('/pages/group/orderDetail?code='+item.order_no)">订单详情
								</view>
							</view>
						</view>
						<!-- <view class="part3 flex-row-between">
						<view class="font12">退款金额：<text class="font14 font-assist">￥209</text></view>
						<view class="font13 font-969696">等待处理</view>
					</view> -->
					</view>
				</block>
			</view>
		</LoadMore>
	</view>
</template>

<script>
	import LoadMore from "@/components/j-loadMore/index.vue";
	export default {
		components: {
			LoadMore
		},
		data() {
			return {
				filterBar: [{
						id: '',
						title: '全部'
					},
					{
						id: 11,
						title: '待付款'
					},
					{
						id: 22,
						title: '拼团中'
					},
					{
						id: 33,
						title: '拼团成功'
					},
					{
						id: 44,
						title: '拼团失败'
					},
					{
						id: 55,
						title: '售后'
					}
				],
				filterCurrent: '', // 高亮的id
				dataList: [], //数据
				userInfo: {
					type: "user"
				},
				imgFullUrl: this.$Config.http_static, //图片地址
				// 传参数据
				initData: {
					url: 'orderList',
					param: {
						pay_status: '',
						pt_status: ''
					}
				},
			}
		},
		onLoad: function(options) {},
		methods: {
			// LoadMore返回列表数据
			dataRefresh(e) {
				var nowTime = Math.round(new Date().getTime());
				e.forEach(item => {
					var ms = (item.spell_info.end_time * 1000) - nowTime;
					var day = Math.floor(ms / (1000 * 60 * 60 * 24));
					var hour = Math.floor(ms / (1000 * 60 * 60)) % 24;
					if (day > 0) {
						hour = (day * 24) + hour
					}
					var minute = Math.floor(ms / (1000 * 60)) % 60;
					var second = Math.floor(ms / 1000) % 60;
					let timeobj = {
						'day': day,
						'hour': hour,
						'minute': minute,
						'second': second,
						'show': ms>0?true:false
					}
					item.timeobj = timeobj
					// pay_status 1=>支付 2=>未支付
					if (item.pay_status == 2) {
						if (item.order_status == 10) {
							item.name_is = '待支付'
							item.down_is = true
						}
						if (item.order_status == 60) {
							item.name_is = '已取消'
							item.down_is = false
						}
					} else {
						item.down_is = false
						//10进行中
						if (item.order_status == 10) {
							// is_spell是否拼团购买 1=>是 2=>不是
							// if (item.is_spell == 1) {
								if (item.spell_info.status == 'normal') {
									item.name_is = '拼团中，还差人' +
										this.$base.numSub(item.spell_info.spell_number, item.spell_info
											.count_user) +
										'成团'
									item.down_is = true
								}
								if (item.spell_info.status == 'hidden') {
									item.name_is = '拼团异常'
								}
								if (item.spell_info.status == 'end') {
									item.name_is = '拼团成功,待发货'
								}
								if (item.spell_info.status == 'deleted') {
									item.name_is = '很遗憾,拼团失败!'
								}
							// } 
							// else {
							// 	item.name_is = '待发货'
							// }
						}
						if (item.order_status == 20) {
							item.name_is = '已发货'
						}
						if (item.order_status == 30) {
							item.name_is = '待评价'
						}
						if (item.order_status == 40) {
							item.name_is = '已评价'
						}
						if (item.order_status == 50) {
							item.name_is = '已完成'
						}
						if (item.order_status == 60) {
							item.name_is = '已取消'
						}
						if (item.order_status == 70) {
							item.name_is = '已退款'
						}
						//售后过
						if (item.refund_status > 10) {
							item.refund_is = true
						}
					}
				})
				this.dataList = e
			},
			// 筛选列表
			filterList(id) {
				if (id == '') {
					this.initData.param.pay_status = ''
					this.initData.param.pt_status = ''
					this.initData.url = 'orderList'
				}
				if (id == 11) {
					this.initData.param.pay_status = 2
					this.initData.param.pt_status = ''
					this.initData.url = 'orderList'
				}
				if (id == 22) {
					this.initData.param.pay_status = 1
					this.initData.param.pt_status = 'normal'
					this.initData.url = 'orderList'
				}
				if (id == 33) {
					this.initData.param.pay_status = 1
					this.initData.param.pt_status = 'end'
					this.initData.url = 'orderList'
				}
				if (id == 44) {
					this.initData.param.pay_status = 1
					this.initData.param.pt_status = 'deleted'
					this.initData.url = 'orderList'
				}
				if (id == 55) {
					this.initData.param.pay_status = ''
					this.initData.param.pt_status = ''
					this.initData.url = 'orderAftermarket'
				}
				this.filterCurrent = id
				this.$refs.LoadMore.oncutRefresh(this.initData)
			},
			// 时间戳转日期
			getDate(time) {
				return this.$base.formatTime(new Date(parseInt(time) * 1000), 'yyyy/MM/dd hh:ss')
			},
			//跳转
			goNext(url) {
				this.$Router.push(url)
			}
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
